package ddd.valueobject;

import lombok.Data;

@Data
public class PhoneNumber {
    private final String phone;

    public PhoneNumber(String phone){
        if (phone == null || phone.equals("")) throw new RuntimeException("phone is null , please valid");
        else if (!isValid(phone)) throw new RuntimeException("phone is error");
        this.phone = phone;
    }

    public boolean isValid(String phone){
        return phone.matches("^0?[1-9]{2,3}-?\\d{8}$");
    }
}
